
;--------------------------------------------------------------------------------
; ***  
; ***  MOVEMENT MACRO DEFINITIONS
; ***  
; ***  These are the macros used in Janggi v.2 to define the movements of the
; ***  various Janggi pieces.
; ***  
;--------------------------------------------------------------------------------

(define shift ($1 (verify not-friend?) add))

;++  If there is no friendly piece in this space, move unit into it

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(define shift-Ma ($1 (verify empty?) $2 (verify not-friend?) add))

;++  For the movement of Horses.  If the space in direction one AND direction two
;++  are both empty, then move the [Horse] piece into space two.

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(define shift-Sang 
       ($1 (verify empty?) $2 (verify empty?) $2 (verify not-friend?) add))

;++  Similar two shift-Ma macro, but checks for two spaces in direction two, not
;++  just one.  For the movement of Elephants.

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(define slide ($1 (while empty? add $1) (verify enemy?) add))

;++  For the movement of Chariots (Rooks).  So long as a stretch of spaces in the
;++  specified directiare empty and without friendly units, the Chariot may move
;++  along that direction.


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(define slide-Po 
        ($1 (while empty? $1) (verify (not-piece? Po)) 
         $1 (while empty? add $1) 
         (verify enemy?) (verify (not-piece? Po)) add))

;++  Similar to the slide macro, but a bit more complex movement definition for
;++  the cannon pieces.  While the spaces along the specified direction are
;++  empty with only one non-cannon piece intervening AND an enemy piece that 
;++  is not another cannon, then your cannon can move there.

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(define opposed-Koung  (n (while empty? n) (verify (piece? Koung)) add))

;++  The 'bare king' rule to disallow opposing kings to face each other along
;++  an empty file of the board.

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(define shift-fortress ($1 (verify (in-zone? fortress)) 
                       (verify not-friend?) add ))

;++  To restrict the movement of Kings and Ministers within the fortress.

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(define EmptySpot (and empty? (not-piece? $1 e) (not-piece? $1 w) ) )

;++  Conditional statement.
;++  True if space is empty and there is NOT a piece specified (i.e. an
;++  horse or an elephant) on either side of that space.

;-----------------------------------------------------------------------

(define Deploy (if (EmptySpot $1) (add $1) ) )

;++  If desired space is empty and does not have a [horse or elephant]
;++  piece on either side, then put it into said space.

;-----------------------------------------------------------------------

(define Steed
        (
         (verify (in-zone? Stable))
                 (if ; any of the Cho drop points needs a Steed
                     (and (or not-enemy? not-adjacent-to-enemy?)
                          (or (empty? b1) (empty? c1) (empty? g1) (empty? h1) )
                          ) ;-- end and block
                     b1 (Deploy $1) c1  (Deploy $1) g1 (Deploy $1) h1 (Deploy $1)
                     ) ;-- end if block
         (verify (in-zone? Stable))
                 (if ; any of the Han drop points needs a Steed
                     (and (or not-enemy? not-adjacent-to-enemy?)
                          (or (empty? b10) (empty? c10) (empty? g10) (empty? h10) )
                          ) ;-- end and block
                     b10 (Deploy $1) c10 (Deploy $1) g10 (Deploy $1) h10 (Deploy $1)
                     ) ;-- end if block
         ) ;-- end verify/if/if block
        ) ;-- end Steed definition

;++  Rather long winded logic for 'dropping' either a Horse or an
;++  Elephant piece from the off-board 'stables' onto the board proper.
;++  It was also necesary to check for the precence of enemy pieces as
;++  Zillions was otherwise prone to positioning some of its Horses or
;++  Elephants on the other player's side of the board.

;-----------------------------------------------------------------------

(define Phony-Ma-moves
        (moves (move-type Mount) (Steed Ma))
        ) ;-- end Phony-Ma-Moves definition

;** Note that all this "piece" can do is 'drop' from the off board 
;** position to its proper place on the board, at which point it 
;** promotes to the real Horse piece.

;-----------------------------------------------------------------------

(define Ma-moves
        (moves (move-type normal) (shift-Ma n ne) (shift-Ma n nw) 
                                  (shift-Ma s se) (shift-Ma s sw)
                                  (shift-Ma e ne) (shift-Ma e se) 
                                  (shift-Ma w nw) (shift-Ma w sw)
                          ) ;-- end move block
        ) ;-- end Ma-moves definition

;-----------------------------------------------------------------------

(define Phony-Sang-moves
        (moves (move-type Mount) (Steed Sang))
        ) ;-- end Phony-Sang-Moves definition

;** Note that all this "piece" can do is 'drop' from the off board 
;** position to its proper place on the board, at which point it 
;** promotes to the real Elephant piece.

;-----------------------------------------------------------------------

(define Sang-moves
          (moves (move-type normal) (shift-Sang n ne) (shift-Sang n nw) 
                                    (shift-Sang s se) (shift-Sang s sw)
                                    (shift-Sang e ne) (shift-Sang e se) 
                                    (shift-Sang w nw) (shift-Sang w sw)
                            ) ;-- end move block
        ) ;-- end Sang-moves definition

;-----------------------------------------------------------------------

(define Tjol-moves
       (moves (move-type normal)
              (shift n) (shift e) (shift w)
              (shift fortress-nw) (shift fortress-ne)
              ) ;-- end move block
        ) ;-- end Tjol-moves definition

;-----------------------------------------------------------------------

(define Tcha-moves
        (moves (move-type normal)
               (slide n) (slide e) (slide s) (slide w)
               (slide fortress-nw) (slide fortress-ne)
               (slide fortress-sw) (slide fortress-se))
        ) ;-- end Tcha-moves definition

;***  Regular rook moves, plus moving along the diagonals of either 
;***  player's fortress

;-----------------------------------------------------------------------

(define Po-moves
        (moves (move-type normal)
               (slide-Po n) (slide-Po e) 
               (slide-Po s) (slide-Po w)
               (slide-Po fortress-nw) (slide-Po fortress-ne)
               (slide-Po fortress-sw) (slide-Po fortress-se))
        ) ;-- end Po-moves definition

;***  Regular cannon moves, plus moving along the diagonals of either 
;***  player's fortress -- in the case of a Janggi fortress, this will
;***  mean it can only move along the fortress diagonal if there is a
;***  screen piece (usually the king) on the central spot inside the
;***  fortress (e2 or e9)

;-----------------------------------------------------------------------

(define Sah-moves
        (moves (move-type normal)
               (shift-fortress n) (shift-fortress e) 
               (shift-fortress s) (shift-fortress w)
               (shift fortress-nw) (shift fortress-ne)
               (shift fortress-sw) (shift fortress-se))
        ) ;-- end Sah-moves definition

;***  Minister moves along any line within the fortress and is confined
;***  to it therefore

;-----------------------------------------------------------------------

(define Koung-moves-nobare
        (moves (move-type normal)
               (opposed-Koung)
               (shift-fortress n) (shift-fortress e)
               (shift-fortress s) (shift-fortress w)
               (shift fortress-nw) (shift fortress-ne)
               (shift fortress-sw) (shift fortress-se))
        ) ;-- end Koung-moves-nobare definition

;***  General moves along any line within the fortress and is confined
;***  to it therefore -- as well as the 'bare king' rule to forbid two
;***  opposing kings lined up along the same file without an intervening
;***  piece.

;-----------------------------------------------------------------------

(define Koung-moves-bare
        (moves (move-type normal)
               (shift-fortress n) (shift-fortress e)
               (shift-fortress s) (shift-fortress w)
               (shift fortress-nw) (shift fortress-ne)
               (shift fortress-sw) (shift fortress-se))
        ) ;-- end Koung-moves-bare definition

;***  General moves along any line within the fortress and is confined
;***  to it therefore -- the only difference between this and the other
;***  King moves is that you can have opposed kings without pieces in
;***  between them.  This does, of course, prevent a lot of checkmates
;***  you would see with the bare king rule.

;-----------------------------------------------------------------------

